var PlayerManager = {
  users: {},

  getUserNumber: function() {
    return Object.keys(this.users).length;
  },

  addUser: function(id, name) {
    this.users[id] = name;
  },

  removeUser: function(id) {
    delete this.users[id];
  },

  clearUsers: function() {
    for (var id in this.users)
      this.removeUser(id);
  },

  getNameById: function(id) {
    return this.users[id];
  },

  getIdByName: function(name) {
    for (var id in this.users) {
      if (this.users[id] == name)
        return id;
    }
    return null;
  },

  hasUserWithId: function(id) {
    return this.users[id] != undefined;
  },
  
  hasUserWithName: function(name) {
    var users = this.users;
    for (var id in users) {
      if (users[id] === name)
        return true;
    }
  }
};

module.exports = PlayerManager;